package com.houseService.serviceCategories.controller;

import com.houseService.common.annotation.Log;
import com.houseService.common.core.controller.BaseController;
import com.houseService.common.core.domain.AjaxResult;
import com.houseService.common.enums.BusinessType;
import com.houseService.common.utils.poi.ExcelUtil;
import com.houseService.serviceCategories.vo.ServiceCategoriesVo;
import com.houseService.serviceCategories.service.IServiceCategoriesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.houseService.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 服务分类管理Controller
 *
 * @author LiuChunlin
 * @date 2025-03-19
 */
@Api(tags = "服务分类管理Controller")
@RestController
@RequestMapping("/serviceCategories/serviceCategories")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class ServiceCategoriesController extends BaseController {

    private final IServiceCategoriesService serviceCategoriesService;

    @ApiOperation("查询服务分类管理列表")
    @PreAuthorize("@ss.hasPermi('serviceCategories:serviceCategories:list')")
    @GetMapping("/list")
    public TableDataInfo<ServiceCategoriesVo> list(ServiceCategoriesVo entity) {
        return serviceCategoriesService.queryList(entity);
    }

    @ApiOperation("查询服务分类管理所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(ServiceCategoriesVo entity) {
        return AjaxResult.success("查询成功", serviceCategoriesService.queryAll(entity));
    }

    @ApiOperation("导出服务分类管理列表")
    @PreAuthorize("@ss.hasPermi('serviceCategories:serviceCategories:export')")
    @Log(title = "服务分类管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceCategoriesVo entity) {
        List<ServiceCategoriesVo> list = serviceCategoriesService.queryAll(entity);
        ExcelUtil<ServiceCategoriesVo> util = new ExcelUtil<>(ServiceCategoriesVo.class);
        util.exportExcel(response, list, "服务分类管理数据");
    }

    @ApiOperation("获取服务分类管理详细信息")
    @PreAuthorize("@ss.hasPermi('serviceCategories:serviceCategories:query')")
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success("查询成功", serviceCategoriesService.queryById(Long.valueOf(id)));
    }

    @ApiOperation("新增服务分类管理")
    @PreAuthorize("@ss.hasPermi('serviceCategories:serviceCategories:add')")
    @Log(title = "服务分类管理", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody ServiceCategoriesVo entity) {
        return toAjax(serviceCategoriesService.save(entity));
    }

    @ApiOperation("修改服务分类管理")
    @PreAuthorize("@ss.hasPermi('serviceCategories:serviceCategories:edit')")
    @Log(title = "服务分类管理", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody ServiceCategoriesVo entity) {
        return toAjax(serviceCategoriesService.updateById(entity));
    }

    @ApiOperation("删除服务分类管理")
    @PreAuthorize("@ss.hasPermi('serviceCategories:serviceCategories:remove')")
    @Log(title = "服务分类管理", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(serviceCategoriesService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
